/*
 * Copyright (c) [2019] Zhang Yansen.All rights reserved.
 *
 * t-console is licensed under the Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

import { alias, getColor } from './color'
import { parse } from './parse'

export function translate(param) {
  if (!param) return;

  const { label, value, type } = param

  const styles = [
    'padding: 1px; border-radius: 3px 0 0 3px; color: #fff; background: ${};',
    'padding: 1px; border-radius: 0 3px 3px 0; color: #fff; background: ${};',
  ]

  return [
    `%c ${label} %c ${value} `,
    styles[0].replace('${}', getColor(alias.default)),
    styles[1].replace('${}', getColor(type || alias.info)),
  ]
}

export function getOut(...args) {
  return translate(parse(...args))
}

export default function badge (...args) {
  console.log(...getOut(...args))
}
